package com.cskaoyan.servlet;

import com.cskaoyan.util.LocalStorage;
import com.cskaoyan.util.URIUtil;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Properties;

/**
 * @author Ramsey
 * @date 2023年05月29日 12:10
 */
@WebServlet("/wx/storage/fetch/*")
public class PhotoServlet extends WdBaseServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入图片访问页面");
        //测试访问路径
        String operation = URIUtil.getOperation(PhotoServlet.class, request);
        operation = operation.replace('/', ' ').trim();//看看这样替换有没有空格
        System.out.println("文件名:" + operation);//文件名
        String path = "e:/storage";
        System.out.println("文件目录:" + path);
        //尝试写入
        FileInputStream inputStream = new FileInputStream(new File(path, operation));
        ServletOutputStream outputStream = response.getOutputStream();
        int length = 0;
        byte[] bytes = new byte[1024];
        while ((length = inputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, length);
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
